﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace Htse.Blue.Logic.Validation
{
	public static class ValidationHelper
	{
		/// <summary>
		/// Validate the string as email address
		/// </summary>
		/// <param name="email"></param>
		/// <returns>True if the mail address is valid</returns>
		public static bool ValidateAsEmail(this string email)
		{
			string pattern = @"^(([^<>()[\]\\.,;:\s@\""]+"
				+ @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
				+ @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
				+ @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
				+ @"[a-zA-Z]{2,}))$";

			Regex regex = new Regex(pattern);

			return regex.IsMatch(email);
		}

		/// <summary>
		/// Validate the string as phone number
		/// </summary>
		/// <param name="phone"></param>
		/// <returns>True if the phone number is valid</returns>
		public static bool ValidateAsPhone(this string phone)
		{
			string pattern = @"\d{8,}";

			Regex regex = new Regex(pattern);

			return regex.IsMatch(phone);
		}
	}
}
